package com.example.academic_affairs_system.mapper.provider;

import org.apache.ibatis.jdbc.SQL;

/**
 * @author hjx
 * @since 2023/02/05 1:24 PM
 */
public class AasStudentCoursesProvider {
  public String getClassStudentCourses() {
    return new SQL() {
      {
        SELECT(
                "au.id as userId",
                "au.username as studentNumber",
                "au.nickname",
                "if(au.sex = 0, '女', '男') as sex",
                "`asc`.grades as grades")
            .FROM("aas_class ac")
            .LEFT_OUTER_JOIN("aas_class_student acs on acs.class_id = ac.id")
            .LEFT_OUTER_JOIN("aas_student_courses `asc` on `asc`.student_id = acs.student_id")
            .LEFT_OUTER_JOIN("aas_user au on au.id = `asc`.student_id ")
            .WHERE("`asc`.courses_id = #{coursesId} and ac.id = #{classId} and ac.enabled = 1");
      }
    }.toString();
  }

  public String getStudentCourses() {
    return new SQL() {
      {
        SELECT(
                "ac.id as coursesId",
                "ac.name as coursesName",
                "ac.`type` as coursesType",
                "ac.`desc` as coursesDesc",
                "asc2.grades")
            .FROM("aas_student_courses asc2")
            .LEFT_OUTER_JOIN("aas_courses ac on asc2.courses_id = ac.id")
            .LEFT_OUTER_JOIN("aas_user au on asc2.student_id = au.id")
            .WHERE("asc2.student_id=#{studentId}")
            .AND()
            .WHERE("asc2.enabled = 1 and ac.enabled = 1 and au.enabled = 1");
      }
    }.toString();
  }
}
